<template>
  <div class="app-container">
    <!-- 工时填报区域 -->
    <el-card class="app-card apple-card">
      <div class="filter-container">
        <el-button type="primary" plain class="apple-button">
          <el-icon><Filter /></el-icon>筛选
        </el-button>
      </div>

      <div class="table-header">
        <div class="left-buttons">
          <!-- 左侧按钮区域 -->
          <el-button type="danger" :disabled="selectedRecords.length === 0" @click="handleBatchDelete" class="apple-button danger-button">
            <el-icon><Delete /></el-icon>批量删除
          </el-button>
        </div>
        <div class="right-buttons">
          <el-button type="primary" @click="handleAdd" class="apple-button primary-button">
            <el-icon><Plus /></el-icon>添加
          </el-button>
          <el-button type="primary" @click="handleImport" class="apple-button primary-button">
            <el-icon><Upload /></el-icon>导入
          </el-button>
          <el-button type="success" @click="handleExport" class="apple-button success-button">
            <el-icon><Download /></el-icon>导出
          </el-button>
        </div>
      </div>
      
      <el-table
        v-loading="loading"
        :data="recordList"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange"
        class="apple-table"
      >
        <el-table-column type="selection" width="45" />
        <el-table-column label="操作" width="130" fixed="left">
          <template #default="scope">
            <el-button type="primary" link @click="handleEdit(scope.row)" class="apple-link-button">编辑</el-button>
            <el-button type="danger" link @click="handleDelete(scope.row)" class="apple-link-button">删除</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="nickname_display" label="员工" min-width="100" />
        <el-table-column prop="login_time" label="上线时间" min-width="150" sortable>
          <template #default="scope">
            {{ formatDateTime(scope.row.login_time) }}
          </template>
        </el-table-column>
        <el-table-column prop="logout_time" label="下线时间" min-width="150" sortable>
          <template #default="scope">
            {{ formatDateTime(scope.row.logout_time) }}
          </template>
        </el-table-column>
        <el-table-column prop="duty_type" label="值班类型" min-width="100">
          <template #default="scope">
            <el-tag :type="getDutyTypeTagType(scope.row.duty_type)" class="apple-tag">
              {{ scope.row.duty_type }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="online_duration" label="在线时长" min-width="100">
          <template #default="scope">
            {{ scope.row.online_duration }}小时
          </template>
        </el-table-column>
      </el-table>
      
      <div class="table-pagination">
        <el-pagination
          v-model:current-page="pagination.page"
          v-model:page-size="pagination.pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pagination.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          class="apple-pagination"
        />
      </div>
    </el-card>

    <!-- 添加/编辑工时记录弹窗 -->
    <el-dialog
      :title="dialogTitle"
      v-model="dialogVisible"
      width="550px"
      append-to-body
      destroy-on-close
      custom-class="apple-dialog"
    >
      <el-form
        ref="formRef"
        :model="form"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="员工" prop="nickname">
          <el-select v-model="form.nickname" placeholder="请选择员工" style="width: 100%" class="apple-select">
            <el-option
              v-for="item in userOptions"
              :key="item.id"
              :label="item.nickname || item.username"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="上线时间" prop="login_time">
          <el-date-picker
            v-model="form.login_time"
            type="date"
            placeholder="选择日期"
            style="width: 50%"
            value-format="YYYY-MM-DD"
            format="YYYY-MM-DD"
            :disabled-date="disableFutureDates"
            class="apple-date-picker"
          />
          <el-time-select
            v-model="form.login_time_hour"
            start="00:00"
            step="01:00"
            end="23:00"
            placeholder="选择小时"
            style="width: 48%; margin-left: 2%"
            format="HH:00"
            class="apple-time-select"
          />
        </el-form-item>
        <el-form-item label="下线时间" prop="logout_time">
          <el-date-picker
            v-model="form.logout_time"
            type="date"
            placeholder="选择日期"
            style="width: 50%"
            value-format="YYYY-MM-DD"
            format="YYYY-MM-DD"
            :disabled-date="disableFutureDates"
            class="apple-date-picker"
          />
          <el-time-select
            v-model="form.logout_time_hour"
            start="00:00"
            step="01:00"
            end="23:00"
            placeholder="选择小时"
            style="width: 48%; margin-left: 2%"
            format="HH:00"
            class="apple-time-select"
          />
        </el-form-item>
        <el-form-item label="值班类型" prop="duty_type">
          <el-select v-model="form.duty_type" placeholder="请选择值班类型" style="width: 100%" class="apple-select">
            <el-option label="正常值班" value="正常值班" />
            <el-option label="临时值班" value="临时值班" />
          </el-select>
        </el-form-item>
        <el-form-item label="在线时长" prop="online_duration">
          <el-input v-model="form.online_duration" disabled class="apple-input">
            <template #append>小时</template>
          </el-input>
          <div class="form-tip">在线时长将根据上线和下线时间自动计算</div>
        </el-form-item>
        <el-form-item label="时薪" prop="hourly_wage">
          <el-input v-model="form.hourly_wage" disabled class="apple-input">
            <template #append>元/小时</template>
          </el-input>
          <div class="form-tip">时薪将根据在线时长自动计算（在线时长 × 5）</div>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="dialogVisible = false" class="apple-button">取消</el-button>
        <el-button type="primary" @click="submitForm" class="apple-button primary-button">提交</el-button>
      </template>
    </el-dialog>

    <!-- 导入工时记录弹窗 -->
    <el-dialog
      title="导入工时记录"
      v-model="importDialogVisible"
      width="600px"
      append-to-body
      destroy-on-close
      class="apple-dialog"
    >
      <el-form
        ref="importFormRef"
        label-width="100px"
      >
        <el-form-item label="模板下载">
          <el-button type="primary" link @click="downloadAttendanceTemplate">
            <el-icon><Download /></el-icon> 下载导入模板.xlsx
          </el-button>
          <div class="upload-tip" style="margin-top: 5px;">
            <p>请先下载模板，按照格式填写数据后上传。</p>
            <p>必需字段：用户昵称, 上线时间, 下线时间, 值班日期, 时薪。</p>
            <p>日期时间格式: YYYY-MM-DD HH:MM:SS (如 2023-01-01 09:00:00)</p>
            <p>日期格式: YYYY-MM-DD (如 2023-01-01)</p>
            <p>在线时长和值班类型会自动计算或可留空。</p>
          </div>
        </el-form-item>
        <el-form-item label="选择文件" prop="file">
          <el-upload
            ref="uploadRef" 
            v-model:file-list="fileList" 
            :on-change="handleFileChange"
            :on-remove="handleFileRemove"
            :before-upload="beforeAttendanceFileUpload"
            :on-exceed="handleFileExceed"
            :limit="1"
            :auto-upload="false" 
            accept=".xlsx,.xls"
            class="apple-upload"
          >
            <el-button type="primary" :icon="Upload">选择Excel文件</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="importDialogVisible = false" class="apple-button">取消</el-button>
          <el-button type="primary" @click="submitAttendanceImport" :loading="importLoading" class="apple-button primary-button">开始导入</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
/* eslint-disable no-undef */
import { ref, reactive, onMounted, watch } from 'vue';
import { Plus, Download, Filter, Delete, Upload } from '@element-plus/icons-vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { getAttendanceList, getAttendance, createAttendance, updateAttendance, deleteAttendance, batchDeleteAttendance, exportAttendance, importAttendance, getAttendanceImportTemplate } from '@/api/attendance';
import { getServiceStaffList } from '@/api/user';

defineOptions({
  name: 'WorkRecordListPage'
});

// 查询参数
const queryParams = reactive({
  page: 1,
  page_size: 10
});

// 表格数据
const recordList = ref([]);
const loading = ref(false);
const selectedRecords = ref([]);
const userOptions = ref([]);

// 分页信息
const pagination = reactive({
  page: 1,
  pageSize: 10,
  total: 0
});

// 表单相关
const dialogVisible = ref(false);
const dialogTitle = ref('添加工时记录');
const formRef = ref(null);
const form = reactive({
  nickname: null,
  login_time: '',
  login_time_hour: '00:00',
  logout_time: '',
  logout_time_hour: '00:00',
  duty_type: '正常值班',
  online_duration: 0,
  hourly_wage: 0
});

// 表单验证规则
const rules = {
  nickname: [{ required: true, message: '请选择员工', trigger: 'change' }],
  login_time: [{ required: true, message: '请选择上线日期', trigger: 'change' }],
  login_time_hour: [{ required: true, message: '请选择上线时间', trigger: 'change' }],
  logout_time: [{ required: true, message: '请选择下线日期', trigger: 'change' }],
  logout_time_hour: [{ required: true, message: '请选择下线时间', trigger: 'change' }],
  duty_type: [{ required: true, message: '请选择值班类型', trigger: 'change' }]
};

// 监听上线时间和下线时间变化，自动计算在线时长和时薪
watch([() => form.login_time, () => form.login_time_hour, () => form.logout_time, () => form.logout_time_hour], 
  ([newLoginDate, newLoginHour, newLogoutDate, newLogoutHour]) => {
  if (newLoginDate && newLoginHour && newLogoutDate && newLogoutHour) {
    // 检查日期是否为同一天
    if (newLoginDate !== newLogoutDate) {
      ElMessage.warning('上线时间和下线时间必须在同一天');
      return;
    }
    
    // 解析小时
    const loginHour = parseInt(newLoginHour.split(':')[0]);
    const logoutHour = parseInt(newLogoutHour.split(':')[0]);
    
    // 检查下线时间是否晚于上线时间
    if (newLoginDate === newLogoutDate && logoutHour <= loginHour) {
      ElMessage.warning('下线时间必须晚于上线时间');
      return;
    }
    
    // 计算时间差（小时）
    const hourDiff = logoutHour - loginHour;
    form.online_duration = hourDiff;
    form.hourly_wage = parseFloat((hourDiff * 5).toFixed(1));
  }
});

// 导入相关状态
const importDialogVisible = ref(false);
const importLoading = ref(false);
const fileList = ref([]);
const selectedFile = ref(null);
const uploadRef = ref(null); // 获取 el-upload 组件实例

// 初始化
onMounted(() => {
  getList();
  loadUserOptions();
});

// 获取工时记录列表
const getList = async () => {
  loading.value = true;
  try {
    const response = await getAttendanceList({
      ...queryParams,
      page: pagination.page,
      page_size: pagination.pageSize
    });
    
    // 检查响应格式
    if (response && response.results) {
      recordList.value = response.results;
      pagination.total = response.count || 0;
    } else if (response && response.data) {
      // 兼容新的响应格式
      recordList.value = response.data.results || [];
      pagination.total = response.data.count || 0;
    } else {
      recordList.value = [];
      pagination.total = 0;
    }
  } catch (error) {
    console.error(error);
    ElMessage.error('获取工时记录失败');
  } finally {
    loading.value = false;
  }
};

// 获取用户选项
const loadUserOptions = async () => {
  try {
    console.log('开始加载用户选项...');
    const response = await getServiceStaffList();
    console.log('获取到用户API响应:', response);
    
    // 添加默认模拟数据，确保选项列表不为空
    userOptions.value = [
      { id: 1, nickname: '默认客服1' },
      { id: 2, nickname: '默认客服2' },
      { id: 3, nickname: '默认客服3' }
    ];
    
    // 尝试从API响应中提取数据
    if (response) {
      let userData = [];
      
      // 处理不同的响应格式
      if (response.data && Array.isArray(response.data)) {
        userData = response.data;
        console.log('使用response.data数组格式');
      } else if (response.data && response.data.items && Array.isArray(response.data.items)) {
        userData = response.data.items;
        console.log('使用response.data.items数组格式');
      } else if (response.results && Array.isArray(response.results)) {
        userData = response.results;
        console.log('使用response.results数组格式');
      } else if (Array.isArray(response)) {
        userData = response;
        console.log('使用直接数组响应格式');
      }
      
      // 如果获取到有效数据，则替换默认数据
      if (userData && userData.length > 0) {
        userOptions.value = userData.map(user => ({
          id: user.id,
          nickname: user.nickname || user.username || `员工${user.id}`
        }));
        console.log('成功格式化用户选项:', userOptions.value);
      } else {
        console.warn('API返回的用户数据为空或格式不正确，使用默认数据');
      }
    }
  } catch (error) {
    console.error('加载用户选项失败:', error);
    // 保留默认数据作为备用
    ElMessage.warning('加载员工列表失败，使用默认数据');
  }
};

// 处理添加
const handleAdd = () => {
  dialogTitle.value = '添加工时记录';
  resetForm();
  dialogVisible.value = true;
};

// 处理编辑
const handleEdit = async (row) => {
  dialogTitle.value = '编辑工时记录';
  resetForm();
  
  try {
    const response = await getAttendance(row.id);
    
    // 检查响应格式
    const data = response.data ? response.data : response;
    
    if (data) {
      // 解析日期和时间
      let loginDate = '';
      let loginHour = '00:00';
      let logoutDate = '';
      let logoutHour = '00:00';
      
      if (data.login_time) {
        const loginDateTime = new Date(data.login_time);
        loginDate = loginDateTime.toISOString().split('T')[0];
        loginHour = `${String(loginDateTime.getHours()).padStart(2, '0')}:00`;
      }
      
      if (data.logout_time) {
        const logoutDateTime = new Date(data.logout_time);
        logoutDate = logoutDateTime.toISOString().split('T')[0];
        logoutHour = `${String(logoutDateTime.getHours()).padStart(2, '0')}:00`;
      }
      
      Object.assign(form, {
        id: data.id,
        nickname: data.nickname,
        login_time: loginDate,
        login_time_hour: loginHour,
        logout_time: logoutDate,
        logout_time_hour: logoutHour,
        duty_type: data.duty_type,
        online_duration: data.online_duration,
        hourly_wage: data.hourly_wage
      });
      dialogVisible.value = true;
    }
  } catch (error) {
    console.error(error);
    ElMessage.error('获取工时记录详情失败');
  }
};

// 处理删除
const handleDelete = (row) => {
  ElMessageBox.confirm('确认要删除该工时记录吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    try {
      await deleteAttendance(row.id);
      ElMessage.success('删除成功');
      getList();
    } catch (error) {
      console.error(error);
    }
  }).catch(() => {});
};

// 处理批量删除
const handleBatchDelete = () => {
  if (selectedRecords.value.length === 0) {
    ElMessage.warning('请至少选择一条记录');
    return;
  }
  
  ElMessageBox.confirm(`确认要删除选中的 ${selectedRecords.value.length} 条记录吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    try {
      const ids = selectedRecords.value.map(item => item.id);
      await batchDeleteAttendance(ids);
      ElMessage.success('批量删除成功');
      getList();
    } catch (error) {
      console.error(error);
      ElMessage.error('批量删除失败');
    }
  }).catch(() => {});
};

// 处理导出
const handleExport = async () => {
  try {
    const response = await exportAttendance(queryParams);
    // 创建Blob链接并下载
    const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    const link = document.createElement('a');
    link.href = URL.createObjectURL(blob);
    link.download = '工时记录数据.xlsx';
    link.click();
    URL.revokeObjectURL(link.href);
  } catch (error) {
    console.error(error);
  }
};

// 提交表单
const submitForm = async () => {
  if (!formRef.value) return;
  
  await formRef.value.validate(async (valid) => {
    if (valid) {
      try {
        // 合并日期和时间
        const loginHour = parseInt(form.login_time_hour.split(':')[0]);
        const logoutHour = parseInt(form.logout_time_hour.split(':')[0]);
        
        // 创建完整的日期时间字符串
        const completeLoginTime = `${form.login_time}T${String(loginHour).padStart(2, '0')}:00:00`;
        const completeLogoutTime = `${form.logout_time}T${String(logoutHour).padStart(2, '0')}:00:00`;
        
        // 创建一个新对象用于提交
        const submitData = {
          ...form,
          login_time: completeLoginTime,
          logout_time: completeLogoutTime
        };
        
        // 删除辅助字段
        delete submitData.login_time_hour;
        delete submitData.logout_time_hour;
        
        console.log('提交数据:', submitData);
        
        if (form.id) {
          await updateAttendance(form.id, submitData);
          ElMessage.success('更新成功');
        } else {
          await createAttendance(submitData);
          ElMessage.success('添加成功');
        }
        dialogVisible.value = false;
        getList();
      } catch (error) {
        console.error(error);
        if (error.response && error.response.data && error.response.data.detail) {
          ElMessage.error(error.response.data.detail);
        } else {
          ElMessage.error('操作失败');
        }
      }
    }
  });
};

// 重置表单
const resetForm = () => {
  form.id = undefined;
  form.nickname = null;
  form.login_time = '';
  form.login_time_hour = '00:00';
  form.logout_time = '';
  form.logout_time_hour = '00:00';
  form.duty_type = '正常值班';
  form.online_duration = 0;
  form.hourly_wage = 0;
  
  if (formRef.value) {
    formRef.value.resetFields();
  }
};

// 处理分页大小变化
const handleSizeChange = (val) => {
  pagination.pageSize = val;
  getList();
};

// 处理页码变化
const handleCurrentChange = (val) => {
  pagination.page = val;
  getList();
};

// 处理选中行变化
const handleSelectionChange = (selection) => {
  selectedRecords.value = selection;
};

// 获取值班类型标签类型
const getDutyTypeTagType = (type) => {
  switch (type) {
    case '正常值班':
      return 'success';
    case '临时值班':
      return 'warning';
    default:
      return 'info';
  }
};

// 禁用未来日期
const disableFutureDates = (date) => {
  return date > new Date();
};

// 格式化日期时间
const formatDateTime = (dateStr) => {
  if (!dateStr) return '';
  const date = new Date(dateStr);
  return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;
};

// 打开导入弹窗
const handleImport = () => {
  fileList.value = []; // 清空文件列表
  selectedFile.value = null;
  importDialogVisible.value = true;
};

// 下载考勤导入模板（通过API获取）
const downloadAttendanceTemplate = () => {
  importLoading.value = true;
  getAttendanceImportTemplate()
    .then(response => {
      const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
      const link = document.createElement('a');
      link.href = URL.createObjectURL(blob);
      link.download = '工时记录导入模板.xlsx';
      link.click();
      URL.revokeObjectURL(link.href);
      ElMessage.success('模板下载成功');
    })
    .catch(error => {
      console.error('下载模板失败:', error);
      ElMessage.error('下载模板失败: ' + (error.message || '未知错误'));
    })
    .finally(() => {
      importLoading.value = false;
    });
};

// 文件选择处理
const handleFileChange = (file) => {
  // ElUpload 的 on-change 会在添加和状态改变时触发，
  // 我们只关心文件准备就绪的状态
  if (file.status === 'ready') {
    selectedFile.value = file; 
  }
};

// 文件移除处理
const handleFileRemove = () => {
  selectedFile.value = null;
};

// 文件超出限制
const handleFileExceed = () => {
  ElMessage.warning('只能选择一个文件进行上传');
};

// 上传前文件验证
const beforeAttendanceFileUpload = (rawFile) => {
  const isExcel = rawFile.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || rawFile.type === 'application/vnd.ms-excel';
  const isLt10M = rawFile.size / 1024 / 1024 < 10; // 限制10MB

  if (!isExcel) {
    ElMessage.error('只能上传 Excel 文件 (.xlsx, .xls)!');
  }
  if (!isLt10M) {
    ElMessage.error('文件大小不能超过 10MB!');
  }
  return isExcel && isLt10M;
};

// 提交导入
const submitAttendanceImport = async () => {
  if (!selectedFile.value) {
    ElMessage.warning('请先选择要导入的文件');
    return;
  }

  importLoading.value = true;
  const formData = new FormData();
  formData.append('file', selectedFile.value.raw); // 使用 .raw 获取原始 File 对象

  try {
    const res = await importAttendance(formData);
    ElMessage.success(`导入成功: ${res.message || '成功导入' + (res.imported_count || '') + '条记录'}`);
    importDialogVisible.value = false;
    fetchAttendanceList(); // 刷新列表
  } catch (error) {
    console.error('导入工时记录失败:', error);
    ElMessage.error(`导入失败: ${error.message || '请检查文件格式和内容'}`);
  } finally {
    importLoading.value = false;
    // 清理上传组件状态，确保下次可以选同一个文件
    if (uploadRef.value) {
       uploadRef.value.clearFiles();
    }
    selectedFile.value = null;
  }
};
</script>

<style scoped>
.filter-container {
  margin-bottom: 20px;
  display: flex;
  justify-content: flex-end;
}

.table-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.left-buttons, .right-buttons {
  display: flex;
  gap: 10px;
}

.table-pagination {
  margin-top: 20px;
  text-align: right;
}

.form-tip {
  font-size: 12px;
  color: #909399;
  line-height: 1.2;
  padding-top: 4px;
}

/* 苹果风格卡片 */
.apple-card {
  border-radius: 12px !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
}

.apple-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12), 0 8px 16px rgba(0, 0, 0, 0.06) !important;
}

/* 苹果风格按钮 */
.apple-button {
  border-radius: 8px !important;
  font-weight: 500 !important;
  transition: background-color 0.3s, transform 0.1s, box-shadow 0.3s !important;
  border: none !important;
  padding: 10px 16px !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08) !important;
}

.apple-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12) !important;
}

.apple-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) !important;
}

.primary-button {
  background-color: #0071e3 !important;
  color: white !important;
}

.primary-button:hover {
  background-color: #0077ed !important;
}

.danger-button {
  background-color: #ff3b30 !important;
  color: white !important;
}

.danger-button:hover {
  background-color: #ff453a !important;
}

.success-button {
  background-color: #34c759 !important;
  color: white !important;
}

.success-button:hover {
  background-color: #30d158 !important;
}

/* 苹果风格表格 */
.apple-table {
  border-radius: 8px !important;
  overflow: hidden;
  border: none !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
}

.apple-table .el-table__header-wrapper {
  background-color: #f5f7fa !important;
}

.apple-table th.el-table__cell {
  background-color: #f5f7fa !important;
  font-weight: 600 !important;
  color: #333 !important;
  padding: 12px 0 !important;
}

.apple-table .el-table__row:hover td {
  background-color: #f5f9fc !important;
}

/* 表格行交替颜色 */
.apple-table .el-table__row:nth-child(odd) {
  background-color: #fafbfc;
}

/* 链接按钮样式 */
.apple-link-button {
  font-weight: 500 !important;
  transition: color 0.3s !important;
}

.apple-link-button:hover {
  text-decoration: underline !important;
}

/* 苹果标签样式 */
.apple-tag {
  border-radius: 12px !important;
  padding: 2px 10px !important;
  font-weight: 500 !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08) !important;
}

/* 苹果风格表单元素 */
.apple-input .el-input__wrapper,
.apple-select .el-input__wrapper,
.apple-date-picker .el-input__wrapper,
.apple-time-select .el-input__wrapper {
  border-radius: 8px !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
  padding: 4px 12px !important;
  transition: box-shadow 0.3s ease !important;
}

.apple-input .el-input__wrapper:hover,
.apple-select .el-input__wrapper:hover,
.apple-date-picker .el-input__wrapper:hover,
.apple-time-select .el-input__wrapper:hover {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15) !important;
}

.apple-input .el-input__wrapper.is-focus,
.apple-select .el-input__wrapper.is-focus,
.apple-date-picker .el-input__wrapper.is-focus,
.apple-time-select .el-input__wrapper.is-focus {
  box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.3) !important;
}

/* 分页控件样式 */
.apple-pagination {
  margin-top: 16px;
  padding: 8px 0;
}

.apple-pagination .el-pagination__sizes .el-input .el-input__wrapper {
  border-radius: 8px !important;
}

.apple-pagination .el-pager li {
  border-radius: 8px !important;
  transition: all 0.3s ease !important;
  margin: 0 3px !important;
}

.apple-pagination .el-pager li.is-active {
  background-color: #0071e3 !important;
  color: white !important;
  font-weight: 600 !important;
}

.apple-pagination .btn-prev,
.apple-pagination .btn-next {
  border-radius: 8px !important;
  transition: all 0.3s ease !important;
}

.upload-tip p {
  margin: 2px 0;
  font-size: 12px;
  color: #909399;
}
</style>

<!-- 添加全局样式 -->
<style>
/* 苹果风格对话框 */
.apple-dialog {
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15), 0 5px 15px rgba(0, 0, 0, 0.08) !important;
}

.apple-dialog .el-dialog__header {
  padding: 16px 20px !important;
  margin: 0 !important;
  border-bottom: 1px solid #f0f0f0 !important;
  background-color: #f5f7fa !important;
}

.apple-dialog .el-dialog__title {
  font-size: 18px !important;
  font-weight: 600 !important;
  color: #333 !important;
}

.apple-dialog .el-dialog__body {
  padding: 20px !important;
}

.apple-dialog .el-dialog__footer {
  padding: 12px 20px 16px !important;
  border-top: 1px solid #f0f0f0 !important;
}

.apple-dialog .el-dialog__headerbtn {
  top: 16px !important;
  right: 16px !important;
}

.apple-dialog .el-dialog__headerbtn:hover .el-dialog__close {
  color: #0071e3 !important;
}

/* 表单元素样式 */
.el-form-item__label {
  font-weight: 500 !important;
  color: #333 !important;
}

/* 时间选择器样式 */
.el-time-select__wrap .el-select-dropdown__item.selected {
  color: #0071e3 !important;
  font-weight: 600 !important;
}

/* 禁用状态输入框样式 */
.el-input.is-disabled .el-input__wrapper {
  background-color: #f5f7fa !important;
}

/* 加载状态样式 */
.el-loading-mask {
  backdrop-filter: blur(4px) !important;
  background-color: rgba(255, 255, 255, 0.6) !important;
}

/* 消息提示框样式 */
.el-message {
  border-radius: 8px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
  padding: 12px 16px !important;
}

.el-message__content {
  font-size: 14px !important;
}

/* 对话框样式 */
.el-message-box {
  border-radius: 12px !important;
  overflow: hidden !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15), 0 5px 15px rgba(0, 0, 0, 0.08) !important;
}

.el-message-box__header {
  padding: 16px 20px !important;
  background-color: #f5f7fa !important;
  border-bottom: 1px solid #f0f0f0 !important;
}

.el-message-box__title {
  font-size: 18px !important;
  font-weight: 600 !important;
  color: #333 !important;
}

.el-message-box__content {
  padding: 20px !important;
  color: #333 !important;
}

.el-message-box__btns {
  padding: 12px 20px 16px !important;
  border-top: 1px solid #f0f0f0 !important;
}

.el-message-box__btns .el-button {
  border-radius: 8px !important;
  font-weight: 500 !important;
  transition: all 0.3s !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08) !important;
}

.el-message-box__btns .el-button--primary {
  background-color: #0071e3 !important;
  border-color: #0071e3 !important;
  color: white !important;
}

.el-message-box__btns .el-button--primary:hover {
  background-color: #0077ed !important;
  border-color: #0077ed !important;
}
</style>

<style>
.app-container {
  padding: 10px;
  
  margin: 0 auto;
}

.app-card {
  width: 100%;
  padding: 12px;
}

.table-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  align-items: center;
}

.table-pagination {
  margin-top: 20px;
}
</style> 